<template>
  <div class="footer-box">
    <div id="divhtml" style="float: left; height: auto; margin-left: 30px; margin-top: 1px; line-height: 20px;">
      <table>
        <template v-for="(directory, index) of list">
          <tr v-if="!directory.name.startsWith('/resource/')">
            <td style="font-weight:bold;font-size:16px;height:40px;">{{directory.name}}</td>
          </tr>
          <template v-if="directory.name.startsWith('/resource/')">
            <tr>
              <td style="font-size:12px;"><a :href="directory.name" :download="directory.name.split('/')[directory.name.split('/').length - 1]" title='点击下载'>{{directory.name.split('/')[directory.name.split('/').length - 1]}}</a></td>
            </tr>
          </template>
          <template v-else>
            <tr v-for="(file, idx) of directory.files">
              <td style="font-size:12px;"><a :href="file.path" :download="file.name" title='点击下载'>{{file.name}}</a></td>
            </tr>
          </template>
        </template>
      </table>
    </div>
  </div>
</template>
<script>
  import http from '@/api/http'
  import Tools from "@/util/Tools.js";
  import config from '@/config'
  export default {
    name: 'GuideBook',
    data(){
        return {
          list: []
        }
    },
    created() {
        http.get(this.$api.API_CONSOLE_GUIDE,{}).then(resp=>{
          resp.map((item, idx) => {
            item.name = item['firstLevelFileName' + idx]
            item.files = []
            if (item.secondLevelFileName) {
              for (let i = 0; i < Object.keys(item.secondLevelFileName).length; i++) {
                let path = item.secondLevelFileName['secondLevelFileName' + i]
                item.files.push({
                  name: path.split('/')[path.split('/').length - 1],
                  path: '/'+path
                })
              }
            } else if (item.name.startsWith('resource/')) {
              item.name = '/' + item.name
            }
            return item;
          })
          this.list = resp
      })
    }
  }
</script>
